package cn.kattomy.shop.category.service.impl;

import java.util.List;

import cn.kattomy.shop.category.dao.CategoryDao;
import cn.kattomy.shop.category.service.CategoryService;
import cn.kattomy.shop.category.vo.Category;
import cn.kattomy.shop.utils.PageBean;

public class CategoryServiceImpl implements CategoryService {

	private CategoryDao categoryDao;
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}

	@Override
	public List<Category> getAll() {
		return categoryDao.queryForAll();
	}

	@Override
	public void save(Category category) {
		categoryDao.save(category);
	}
	
	@Override
	public void update(Category category) {
		categoryDao.update(category);
	}

	@Override
	public Category findByCid(Integer cid) {
		return categoryDao.findByCid(cid);
	}

	@Override
	public void delete(Category category) {
		categoryDao.delete(category);
	}

	@Override
	public PageBean<Category> findAll(Integer pageNo) {
		int pageSize = 10;
		PageBean<Category> pageBean = new PageBean<>(pageNo, pageSize);
		pageBean.setTotalItemNo(categoryDao.findCount());
		int begin = (pageNo - 1) * pageSize;
		List<Category> list = categoryDao.findByPage(begin, pageSize);
		pageBean.setList(list);
		return pageBean;
	}


}
